package com.example.design.singleton;

/**
 * 静态内部类方式，Singleton1 的改良版
 * JVM 保证单例
 * 加载外部类时不会加载内部类，这样可以实现懒加载
 */
public class Singleton3 {
    private Singleton3() {}
    private static class SingletonHolder {
        private static final Singleton3 INSTANCE = new Singleton3();
    }
    public static Singleton3 getInstance() {
        return SingletonHolder.INSTANCE;
    }
    public void m() {
        // ...
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                System.out.println(Singleton3.getInstance().hashCode());
            }).start();
        }
    }
}
